<?php
include ('common/constants.php');
include ('common/db.php');
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body>
<?php 
  
  $sql = " SELECT a.advertisement_type, sl.advert_id as id, sl.seat_no seats, sl.action, (select name from user where email=sl.user_id) as name, sl.user_id as email FROM `notification` sl, `advertisement` a  ";
  $sql .= " WHERE sl.advert_id = a.advert_id AND a.email='{$_SESSION['user_email']}'; ";

  ?>
    <!-- Notification Panel -->
    <div id="notifPanel" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">Notifications</h3>
        </div>
        <div class="modal-body">
        	<table class="table table-hover">
              <thead>
                <tr>
                  <th>Advert/Post</th>
                  <th>Contact</th>
                  <th>Action</th>
                  <th>Seat(s)</th>
                </tr>
              </thead>
              <tbody>
              <?php
                $result = mysql_query($sql) or trigger_error(mysql_error());
                $num = mysql_num_rows($result);
                $i = 0;

                for ($i=0; $i < $num; $i++){
                ?>
                  <tr>
                    <td> <a href="view_advertiesement.php?advert_id=<?php echo mysql_result($result,$i,"id"); ?>&advert_type=<?php echo mysql_result($result,$i,"advertisement_type"); ?>"><?php echo mysql_result($result,$i,"id"); ?></a></td>
                    <td> <a href="user_view.php?user_id=<?php echo mysql_result($result,$i,"email"); ?>"><?php echo mysql_result($result,$i,"name"); ?></a></td>
                    <td><?php if (mysql_result($result,$i,"action")=="liked") { echo "liked"; } elseif (mysql_result($result,$i,"advertisement_type")=="advert") { echo "reserved"; } elseif (mysql_result($result,$i,"advertisement_type")=="post") {  echo "accepted"; } ?></td>
                    <td><?php if (mysql_result($result,$i,"action")=="liked") { echo "--"; } elseif (mysql_result($result,$i,"action")=="reserved") {
                    echo mysql_result($result,$i,"seats"); } ?></td>
                  </tr>
                <?php
                }
                ?>
              </tbody>
            </table>
        </div>
        <div class="modal-footer">
        <button class="btn btn-inverse" data-dismiss="modal" aria-hidden="true">Close</button>
        </div>
    </div>
</body>
</html>
